﻿'© 2004 - 2008 ActiveModules, Inc. All Rights Reserved

Imports System.Text

Namespace DotNetNuke.Modules.ActiveForums
    Partial Public Class admin_home_new
        Inherits ActiveAdminBase
#Region "Event Handlers"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            BindDashboard()
        End Sub
#End Region
#Region "Private Methods"
        Private Sub BindDashboard()
            Dim ds As DataSet = DataProvider.Instance.Dashboard_Get(PortalId, ModuleId)
            If Not ds Is Nothing Then
                BindRecentTopics(ds.Tables(0))
                BindRecentMembers(ds.Tables(1))
                BindTopForums(ds.Tables(2))
                BindTopMembers(ds.Tables(3))
                BindQuickStats(ds.Tables(4))
            End If
#If SKU <> "LITE" Then
            LoadQuickLinks()
#End If
        End Sub
#If SKU <> "LITE" Then
        Private Sub LoadQuickLinks()
            Dim sb As New StringBuilder(1024)
            sb.Append("<table cellpadding=""0"" cellspacing=""0"" class=""dashOuter"" style=""width:200px"">")
            sb.Append("<tr><td class=""dashOuterHeader"">[RESX:QuickLinks]</td></tr><tr><td>")
            sb.Append("<table class=""dashInner"" cellpadding=""2"" style=""width:100%"">")
            sb.Append("<tr><td class=""dashRow""><a href=""javascript:void(0);"" onclick=""LoadView('manageforums_forumeditor','0|G');"">[RESX:NewForumGroup]</a><br /></td>")
            sb.Append("</tr><tr><td class=""dashRow""><a href=""javascript:void(0);"" onclick=""LoadView('manageforums_forumeditor','0|F');"">[RESX:NewForum]</a><br /></td>")
            sb.Append("</tr></table></td></tr></table>")
            litQuickLinks.Text = sb.ToString
        End Sub
#End If

        Private Sub BindRecentTopics(ByVal dt As DataTable)
            Dim sb As New StringBuilder(1024)
            Dim rows As Integer = 0
            sb.Append("<table class=""dashInner"" cellpadding=""2"" width=""100%"">")
            sb.Append("<tr><td class=""dashHD"">[RESX:Topic]</td><td class=""dashHD"">[RESX:Author]</td></tr>")
            Dim dr As DataRow
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    sb.Append("<tr>")
                    sb.Append("<td class=""dashRow"">" & dr("Subject").ToString & "</td>")
                    sb.Append("<td class=""dashRow"">" & dr("DisplayName").ToString & "</td>")
                    sb.Append("</tr>")
                Next
            Else
                sb.Append("<tr><td colspan=""2"" class=""dashRow"">[RESX:NoTopics]</td></tr>")
            End If
            sb.Append("</table>")
            litRecentTopics.Text = sb.ToString
        End Sub
        Private Sub BindRecentMembers(ByVal dt As DataTable)
            Dim sb As New StringBuilder(1024)
            Dim rows As Integer = 0
            sb.Append("<table class=""dashInner"" cellpadding=""2"" width=""100%"">")
            sb.Append("<tr><td class=""dashHD"">[RESX:Date]</td><td class=""dashHD"">[RESX:Name]</td><td class=""dashHD"">[RESX:UserName]</td></tr>")
            Dim dr As DataRow
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    sb.Append("<tr>")
                    'TODO - Fix date time format
                    sb.Append("<td class=""dashRow"">" & CDate(dr("CreatedDate")).ToShortDateString & "</td>")
                    sb.Append("<td class=""dashRow"">" & dr("FirstName").ToString & " " & dr("LastName").ToString & "</td>")
                    sb.Append("<td class=""dashRow"">" & dr("Username").ToString & "</td>")
                    sb.Append("</tr>")
                Next
            Else
                sb.Append("<tr><td colspan=""3"" class=""dashRow"">[RESX:NoMembers]</td></tr>")
            End If
            sb.Append("</table>")
            litRecentMembers.Text = sb.ToString
        End Sub
        Private Sub BindTopForums(ByVal dt As DataTable)
            Dim sb As New StringBuilder(1024)
            Dim rows As Integer = 0
            sb.Append("<table class=""dashInner"" cellpadding=""2"" width=""100%"">")
            sb.Append("<tr><td class=""dashHD"">[RESX:ForumName]</td><td class=""dashHD"" align=""center"" style=""text-align:center;"">[RESX:Topics]</td><td class=""dashHD"" align=""center"" style=""text-align:center;"">[RESX:Replies]</td></tr>")
            Dim dr As DataRow
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    sb.Append("<tr>")
                    sb.Append("<td class=""dashRow"">" & dr("ForumName").ToString & "</td>")
                    sb.Append("<td class=""dashRow"" align=""center"" style=""text-align:center;"">" & dr("TotalTopics").ToString & "</td>")
                    sb.Append("<td class=""dashRow"" align=""center"" style=""text-align:center;"">" & dr("TotalReplies").ToString & "</td>")
                    sb.Append("</tr>")
                Next
            Else
                sb.Append("<tr><td colspan=""3"" class=""dashRow"">[RESX:NoForums]</td></tr>")
            End If
            sb.Append("</table>")
            litTopForums.Text = sb.ToString
        End Sub
        Private Sub BindTopMembers(ByVal dt As DataTable)
            Dim sb As New StringBuilder(1024)
            Dim rows As Integer = 0
            sb.Append("<table class=""dashInner"" cellpadding=""2"" width=""100%"">")
            Dim dr As DataRow
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    sb.Append("<tr>")
                    'TODO - Fix display name
                    sb.Append("<td class=""dashRow"">" & dr("DisplayName").ToString & "</td>")
                    sb.Append("</tr>")
                Next
            Else
                sb.Append("<tr><td class=""dashRow"">[RESX:NoMembers]</td></tr>")
            End If
            sb.Append("</table>")
            litTopMembers.Text = sb.ToString
        End Sub
        Private Sub BindQuickStats(ByVal dt As DataTable)
            Dim sb As New StringBuilder(1024)
            Dim rows As Integer = 0
            sb.Append("<table class=""dashInner"" cellpadding=""2"" width=""100%"">")
            Dim dr As DataRow
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    sb.Append("<tr><td class=""dashHD"">[RESX:TotalForums]</td><td class=""dashRow"" style=""text-align:right"">" & dr("TotalForums").ToString & "</td></tr>")
                    sb.Append("<tr><td class=""dashHD"">[RESX:TotalTopics]</td><td class=""dashRow"" style=""text-align:right"">" & dr("TotalTopics").ToString & "</td></tr>")
                    sb.Append("<tr><td class=""dashHD"">[RESX:TotalReplies]</td><td class=""dashRow"" style=""text-align:right"">" & dr("TotalReplies").ToString & "</td></tr>")
                    sb.Append("<tr><td class=""dashHD"">[RESX:TotalMembers]</td><td class=""dashRow"" style=""text-align:right"">" & dr("TotalMembers").ToString & "</td></tr>")
                    sb.Append("<tr><td class=""dashHD"">[RESX:TotalActiveMembers]</td><td class=""dashRow"" style=""text-align:right"">" & dr("TotalActiveMembers").ToString & "</td></tr>")
                Next
            Else
                sb.Append("<tr><td class=""dashRow"">[RESX:NoData]</td></tr>")
            End If
            sb.Append("</table>")
            litQuickStats.Text = sb.ToString
        End Sub
#End Region

    End Class
End Namespace
